package com.youngjun.generator;

public class StringUtils {


    /**
     * 将下划线分割转换成单词首字母大写
     *
     * @param str
     * @return
     */
    public static String capitalize(String str) {
        if (str == null) return null;
        String[] arrs = str.split("_");
        StringBuilder result = new StringBuilder();

        for (String arr : arrs) {
            String tmp1 = arr.toLowerCase();
            result.append(String.valueOf(tmp1.charAt(0)).toUpperCase()).append(tmp1, 1, tmp1.length());
        }
        return result.toString();
    }

    /**
     * 转换为驼峰格式
     *
     * @param str
     * @return
     */
    public static String camelCase(String str) {
        String tmp1 = capitalize(str);
        return new StringBuilder().append(String.valueOf(tmp1.charAt(0)).toLowerCase()).append(tmp1, 1, tmp1.length()).toString();
    }

}
